<?php
require_once 'error.php';
require_once FILE_DB_TICKETSYSTEEM;
require_once DIR_DEFINES. 'db_constants.php';
require_once DIR_DEFINES. 'constants.php';

/**
 * This is the class that facilitates
 *  the ticketsysteem functionality.
 *
 * @author JDuysserinck
 * @version 0.1
 * 
 * Version History :
 * 0.1  Initial version.
 * 0.2 Added set and get functions
 * 0.3 Connected setters with Save function
 */
class TicketSysteem extends Error {

    private $ticket_id;
    private $pers_id;
    private $status_id;
    private $loc_id;
    private $loc_name;
    private $prio_id;
    private $title;
    private $desc;
    private $prog;
    private $createtime;
    private $endtime;
    private $afdeling;
    

    /**
     *
     * @param int $ticket_id optional or current ticket_id
     */
    public function TicketSysteem($ticket_id=''){
        if ( !empty($ticket_id) ){
            /* Load class vars */
            $db = new DbTicketSysteem($ticket_id);
            if ((!$db === FALSE) || ($db === '')){
                $this->ticket_id = $ticket_id;
                $this->getTicketId($ticket_id);
            
            }

            
        }
    }
 public function getTicketId(){
                            return $this->ticket_id;
                        }
    /**
     * saveTicket uses the save function in db_ticketsysteem to make a new row
     * @param int $status_id Id from database ticket_status
     * @param int $prio_id Id from database ticket_prio
     * @param int $loc_id Id from database ticket_loc
     * @param string $title title of the ticket
     * @param string $desc description of the ticket
     * @param string $prog progress of the ticket
     * @param timestamp $endtime ending time of the ticket (later used in the update)
     */
    public function saveTicket(){
        $db_ticketsysteem = new DbTicketsysteem();

        if (!$db_ticketsysteem->save( $db_ticketsysteem->getTicketId(),/*$this->status_id,*/$this->loc_id,$this->prio_id,$this->title,$this->desc, $this->prog, $this->endtime, $this->afdeling)){
            $this->setErrorArray($db_ticketsysteem->getErrorArray());
            return FALSE;
        } 
        $this->ticket_id = $db_ticketsysteem->getTicketId();
        return TRUE;
    }
      /**
     * updTicket uses the updateTicket function in db_ticketsysteem to update a row
     * @param int $status_id Id from database ticket_status
     * @param int $prio_id Id from database ticket_prio
     * @param int $loc_id Id from database ticket_loc
     * @param string $title title of the ticket
     * @param string $desc description of the ticket
     * @param string $prog progress of the ticket
     * @param timestamp $endtime when a ticket closes, fill in endtime
     */
     public function updTicket(){
         $db_ticketsysteem = new DbTicketsysteem($this->ticket_id);
         
         if (!$db_ticketsysteem->updateTicket( $this->status_id,$this->loc_id,$this->prio_id,$this->title,$this->desc, $this->prog, $this->endtime)){
            $this->setErrorArray($db_ticketsysteem->getErrorArray());
            return FALSE;
        } 
        
        return TRUE;
     }
     //setter for $status_id
public function setStatusId($status_id){
        if (!empty($status_id)){
            $this->status_id = trim($status_id);
            return TRUE;
        } 
        return FALSE;
        
    }
     public function setStatusName($status_name){
          $status_name = new Status();
        if (!empty($status_name)){
            $this->status_name = ($status_name);
            $loc_name->getStatusIdByName();
            return TRUE;
        }
     }
    //setter for $loc_id
    public function setLocId($loc_id){
        if (!empty($loc_id)){
            $this->loc_id = trim($loc_id);
            return TRUE;
        }
        return FALSE;  
    }
    
 
    //setter for $prio_id
    public function setPrioId($prio_id){
        if (!empty($prio_id)){
            $this->prio_id = trim($prio_id);
            return TRUE;
        } 
        return FALSE;
        
    }
    
      public function setPrioName($prio_name){
          $prio_name = new Prioriteit();
        if (!empty($prio_name)){
            $this->prio_name = ($prio_name);
            $loc_name->getPrioIdByName();
            return TRUE;
        }
        return FALSE;  
    }
    //setter for $title
       public function setTitle($title){
        if (!empty($title)){
            $this->title = $title;
            return TRUE;
        } 
        return FALSE;
        
    }
    //setter for $desc
     public function setDesc($desc){
        if (!empty($desc)){
            $this->desc = $desc;
            return TRUE;
        } 
        return FALSE;
        
    }
    //setter for $prog
     public function setProg($prog){
       
      if (!empty($prog)){
            $this->prog = $prog;
            return TRUE;
        } 
        return FALSE;
    }
    
        //setter for $afdeling
     public function setAfdeling($afdeling){
       
      if (!empty($afdeling)){
            $this->afdeling = $afdeling;
            return TRUE;
        } 
        return FALSE;
    }
    
    //getter for $endtime
    public function setEndTime($endtime){
      
	 if (!empty($endtime)){
            $this->endtime = $endtime;
            return TRUE;
        } 
        return FALSE;
        
    }

    
        //getter for pers_id
            public function getPersId()

	{

		return $this->pers_id;

	}  
        //getter for status_id
    public function getStatusId()

	{

		return $this->status_id;

	}  
        //getter for loc_id
        public function getLocId()

	{

		return $this->loc_id;

	}
//getter for prio_id
          public function getPrioId()

	{

		return $this->prio_id;

	}
        //getter for title
          public function getTitle()

	{

		return $this->title;

	}
        //getter for desc
          public function getDesc()

	{

		return $this->desc;

	}
        //getter for prog
          public function getProg()

	{

		return $this->prog;

	}
        //getter for createtime
          public function getCreateTime()

	{

		return $this->createtime;

	}
        //getter for endtime
          public function getEndTime()

	{

		return $this->endtime;

	}
        

}
class TestTicketSysteem {
    
    //tests van setters, select, save en update
    
    public function testTicketsysteem(){

       echo "Test 2 select functie<br />";
        $test2 = new DbTicketsysteem();
        

       echo "ID: " . $test2->getTicketId() . "<BR>" ;
       echo "STATUS ID " . $test2->getStatusId() . "<BR>";
       echo "PERSOON ID: " . $test2->getPersId() . "<BR>";
       echo "LOC ID: " . $test2->getLocId() . "<BR>";
       echo "PRIO ID: " . $test2->getPrioId() . "<BR>";
       echo "TICKET TITEL: " . $test2->getTickettitel() . "<BR>";
       echo "TICKET BESCHRIJVING: " . $test2->getTicketbeschrijving() . "<BR>";
       echo "TICKET VOORTGANG: " . $test2->getTicketProgress() . "<BR>";
       echo "TICKET CREATE TIJD: " . $test2->getTicketCreate() . "<BR>";
       echo "TICKET END TIJD: " . $test2->getTicketEnd() . "<BR>";
 
        echo "<pre>";
        var_dump($test2);
        echo "</pre>";
    
         echo "Test 3 save functie<br />";
        $test3 = new Ticketsysteem();

        
        $test3->setStatusId(1);
        $test3->setLocId(1);
        $test3->setPrioId(1);
        $test3->setTitle('titel');
        $test3->setDesc('beschrijving');
        $test3->setProg('progress');
        $test3->setEndTime(1);
        $test3->saveTicket();
           echo "<pre>";
        var_dump($test3);
        echo "</pre>";
      
            echo "Test 4 update functie<br />";
        $test4 = new Ticketsysteem(1);

        
        $test4->setStatusId(1);
        $test4->setLocId(1);
        $test4->setPrioId(1);
        $test4->setTitle('titel');
        $test4->setDesc('beschrijving');
        $test4->setProg('progress');
        $test4->setEndTime(1);
        $test4->updTicket();
           echo "<pre>";
        var_dump($test4);
        echo "</pre>";
        
        echo "Test 5 locatie<br />";
        $test5 = new Location();
$loc_name="Receptie";
        
       $test5 ->getLocIdByName($loc_name);
           echo "<pre>";
        var_dump($test5);
        echo "</pre>";
    }

}
?>
